<?php
/**
 *栏目管理控制器
 
 */
namespace Admin\Controller;
use Admin\Controller;
	class CategoryController extends AuthController{
		protected $db;
<<<<<<< HEAD
		// protected $cid;
		public function _initialize(){
			$this->db=D('Category');
			// $this->cid=I('cid',0,'intval');
=======
		public function _initialize(){
			$this->db=D('Category');
>>>>>>> 0f5c3357c78f1b2ca73dee4bb54edd8abf9a2b85
		}
		/**
		 * [index 栏目列表]
		 * @return [type] [description]
		 */
		public function index(){
<<<<<<< HEAD
			//实例化Data类
			$Data=new \Think\Data();
			//获得所有的栏目数据
			$categorydata=$this->db->select();
			$catdata=$Data->tree($categorydata,'cat_name');
			foreach ($catdata as $id => $value) {
				$cache[$value['cid']]=$value;
			}
			$this->assign('cache',$cache);
=======
			
>>>>>>> 0f5c3357c78f1b2ca73dee4bb54edd8abf9a2b85
			$this->display();
		}

		/**
		 * [add 添加栏目]
		 */
		public function add(){
<<<<<<< HEAD
			$cid=I('get.cid',0,'intval');
			if(IS_POST){
				if($this->db->create()){
					if($this->db->add()){
						$this->success('添加成功',U('Category/index'));
					}else{
						$this->error('添加失败');
					}
				}else{
					$this->error($this->db->getError());
				}
			}
			if($cid){
				//实例化Data类
				$Data=new \Think\Data();
				//获得所有的栏目数据
				$categorydata=$this->db->select();
				$catdata=$Data->tree($categorydata,'cat_name');
				foreach ($catdata as $id => $value) {
					$pcategorydata[$value['cid']]=$value;
				}
				//分配当前栏目id
				$this->assign('pid',$cid);
				$this->assign('pcategorydata',$pcategorydata);
=======
			if(IS_POST){
				P($_POST);
				if($this->db->create()){
					$this->db->add();
				}
>>>>>>> 0f5c3357c78f1b2ca73dee4bb54edd8abf9a2b85
			}
			$this->display();
		}

		/**
		 * [eidt 编辑栏目]
		 * @return [type] [description]
		 */
		public function edit(){
<<<<<<< HEAD
			$cid=I('get.cid',0,'intval');
			if(IS_POST){
				if($this->db->create()){
					if($this->db->save()){
						$this->success('修改成功',U('Category/index'));
					}else{
						$this->error('修改失败');
					}	
				}else{
					$this->error($this->db->getError());
				}	
			}else{
				$map['cid']=$cid;
				// 获得当前栏目数据
				$categorydata=$this->db->where($map)->find();
				//实例化Data类
				$Data=new \Think\Data();
				//获得所有的栏目数据
				$pcategorydata=$this->db->select();
				$catdata=$Data->tree($pcategorydata,'cat_name');
				foreach ($catdata as $id => $value) {
					$pcategory[$value['cid']]=$value;
				}
				$this->assign('pcategorydata',$pcategory);
				$this->assign('categorydata',$categorydata);
			}
			$this->display();
		}

		public function delete(){
			$cid=I('get.cid',0,'intval');
			//实例化Data类
			$Data=new \Think\Data();
			
			//获得所有的栏目数据
			$categorydata=$this->db->select();
			$catdata=$Data->tree($categorydata,'cat_name');
			foreach ($catdata as $id => $value) {
				$cache[$value['cid']]=$value;
			}
		}

=======
			$this->display();
		}

>>>>>>> 0f5c3357c78f1b2ca73dee4bb54edd8abf9a2b85
}

